package com.example.service.impl;

import com.example.pojo.User;
import com.example.pojo.vo.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Slf4j
@Service
public class UserDetailServiceImpl implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        if (!username.equals("xiaoming")) {
            throw new UsernameNotFoundException("用户名或密码错误");
        }
        User user = new User(1, username, "$2a$10$UKNVCVnhf7htuInarOWHhOxDonylX86RCe7pCHJQaRad7rb8Kk65a", "ROLE_USER",
                true);
        // 查询对应的权限信息
        List<String> permissions = new ArrayList<>(Arrays.asList("system:user:list", "system:user:add", "system:user" +
                ":edit", "system:user:delete"));
        return new LoginUser(user, permissions);
    }
}
